package com.huiquan.analysis.dao;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class AnalysisOutsourcingDao extends BaseDao {
	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "ANALYSIS_OUTSOURCING.";

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> retrieveSidAndSentence() {

		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_SID_AND_SENTENCE", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveBankVocabularys() {

		return (List<String>) this.list(space + "RETRIEVE_BANK_VOCABULARYS", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveOriginalVocabularys() {

		return (List<String>) this.list(space + "RETRIEVE_ORIGINAL_VOCABULARYS", sqlMapClient);
	}

	public void batchInsertTempVocab(List<Map<String, Object>> list) {
		int start = 0, end, size = list.size();
		List<Map<String, Object>> tempList;

		while (start < size) {
			if (start + 2000 < size) {
				end = start + 2000;
			} else {
				end = size;
			}
			tempList = list.subList(start, end);
			this.insert(space + "BATCH_INSERT_TEMP_VOCAB", tempList, sqlMapClient);
			start += 2000;
		}
	}

	public void deleteVocabExists() {
		this.delete(space + "DELETE_VOCAB_EXISTS", sqlMapClient);
	}

	public void batchInsertVocabExists(List<Map<String, Object>> list) {

		int start = 0, end, size = list.size();
		List<Map<String, Object>> tempList;

		while (start < size) {
			if (start + 5000 < size) {
				end = start + 5000;
			} else {
				end = size;
			}
			tempList = list.subList(start, end);
			this.insert(space + "BATCH_INSERT_VOCAB_EXISTS", tempList, sqlMapClient);
			start += 5000;
		}
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> retrieveVocabularysByExists() {

		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_VOCABULARYS_BY_EXISTS", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> retrieveTempVocabularys() {

		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_TEMP_VOCABULARYS", sqlMapClient);
	}

}
